package cn.mxz.robots.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.mxz.robots.pojo.Student;
import cn.mxz.robots.util.Encrypt;
import cn.mxz.robots.web.service.GkService;
import cn.mxz.robots.web.service.RdsService;

/**
 * 高考接口控制器
 * 
 * @author cuizhennan<cuizhennan@mouge.wang>
 * @since 2015-06-19
 */
@Scope("prototype")
@Controller
public class GkController
{
	@Autowired
	private GkService gkService;
	@Autowired
	private RdsService rdsService;

	/**
	 * @function 获取省份配置信息
	 */
	@ResponseBody
	@RequestMapping(value = "/gk-provconf/{year}/{province}", method = RequestMethod.GET)
	public String queryProvince(@PathVariable String year, @PathVariable String province)
	{
		return rdsService.getProvconf(year, province);
	}

	/**
	 * @function 获取验证码
	 */
	@ResponseBody
	@RequestMapping(value = "/gk-captcha/{provinceId}/{idCard}", method = RequestMethod.GET)
	public String getCaptcha(@PathVariable String provinceId, @PathVariable String idCard)
	{
		return gkService.forwardService(provinceId, "getCaptcha", new Student("", "", Encrypt.hex2Dec(idCard), "", ""), null);
	}

	/**
	 * @function 登录
	 */
	@ResponseBody
	@RequestMapping(value = "/gk-login/{provinceId}/{idCard}", method = RequestMethod.POST)
	public String login(@PathVariable String provinceId, @PathVariable String idCard, @RequestParam("studentid") String studentid, @RequestParam("studentpwd") String studentpwd,
			@RequestParam("accountnum") String accountnum, @RequestParam("captcha") String captcha, @RequestParam("type") String type)
	{
		return gkService.forwardService(provinceId, "login", new Student(Encrypt.hex2Dec(studentid), Encrypt.hex2Dec(studentpwd), Encrypt.hex2Dec(idCard), Encrypt.hex2Dec(accountnum), type), captcha);
	}

	/**
	 * @function 成绩查询
	 */
	@ResponseBody
	@RequestMapping(value = "/gk-score/{token}", method = RequestMethod.GET)
	public String query(@PathVariable String token)
	{
		return gkService.queryService("score", token);
	}

	/**
	 * @function 成绩分析
	 */
	@ResponseBody
	@RequestMapping(value = "/gk-analysis/{token}", method = RequestMethod.GET)
	public String queryAnalysis(@PathVariable String token)
	{
		return gkService.queryService("analysis", token);
	}

	@ResponseBody
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String index()
	{
		return "[Vesion-25] Current time is " + System.currentTimeMillis();
	}
}
